const path = require("path");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
module.exports = {
    entry:{
        index: "./js/index.js",
    },
    output: {
        filename:"js/[name].bundle.js", //不能是绝对地址
        path:path.join(__dirname,"dist")//__dirname是webpack.conf.js同级目录,　
        //小知识： path.join()方法是将多个参数字符串合并成一个路径字符串。path.resolve()方法是以程序为根目录，作为起点，根据参数解析出一个绝对路径
    },
    module:{//处理js以外的文件
        rules:[
            {
                test:/\.css$/,
                use:['style-loader','css-loader']//处理css
            },
            {
                test: /\.(gif|png|jpe?g|svg)$/i,
                exclude: /(node_modules|bower_components)/,
                use: [
                    {
                        loader: 'url-loader',
                        options: {
                            limit: 8 * 1024,
                            name: `images/[name]-[hash:7].[ext]`,
                        }
                    }
                ]
            },
            {
                test: /\.(woff|svg|eot|ttf)\??.*$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: 'url-loader',
                    options: {
                        name: `font/[name].[hash:7].[ext]`,
                        limit: 8192
                    }
                }
            },
        ]
    },
    plugins:[
        new HtmlWebpackPlugin({
            title:'wq',
            template:'./index.html',
            filename:"[name].html",
            chunks: ["index"]
        }),
        new webpack.HotModuleReplacementPlugin()
    ],
    devServer:{
        // contentBase:path.join(__dirname,'js'),//包含哪个文件夹，默认包含同级文件夹
        host:'localhost',   //服务器的ip地址
        // compress:true, // 代码是否压缩
        port:9000, // 端口号
        open:true,  //自动打开页面
        hot: true,
        proxy: { // 代理
            "0.html": {
                target: "http://localhost:9000",
                pathRewrite: {"0.html" : "0.html"}
            }
        }
    }
}
